import * as api from './api';
import { dict, UserPageQuery, AddReq, DelReq, EditReq, compute, CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud';
import { request } from '/@/utils/service';
import { dictionary } from '/@/utils/dictionary';
import { successMessage } from '/@/utils/message';
import {inject} from "vue";
import { auth, auths, authAll } from '/@/utils/authFunction';
import { useRouter, useRoute } from 'vue-router'
export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
	const pageRequest = async (query: UserPageQuery) => {
		return await api.GetList(query);
	};
	const editRequest = async ({ form, row }: EditReq) => {
		form.id = row.id;
		return await api.UpdateObj(form);
	};
	const delRequest = async ({ row }: DelReq) => {
		return await api.DelObj(row.id);
	};
	const addRequest = async ({ form }: AddReq) => {
		return await api.AddObj(form);
	};

	//权限判定
	// const hasPermissions = inject("$hasPermissions")
	// const hasPermissions = (per:string)=>true

	const router = useRouter()
	return {
		crudOptions: {
			request: {
				pageRequest,
				addRequest,
				editRequest,
				delRequest,
			},
			rowHandle: {
				//固定右侧
				show:false,
				fixed: 'right',
				width: 150,
				buttons: {
					view: {
						show: false,
					},
					edit: {
						show:false
					},
					remove: {
						show:false
					},
				},
			},
			actionbar:{
				show:false
			},
			form: {
				col: { span: 24 },
				labelWidth: '110px',
				wrapper: {
					is: 'el-dialog',
					width: '600px',
				},
			},
			search:{
				disabled:false,
			},
			columns: {
				_index: {
					title: '序号',
					form: { show: false },
					column: {
						//type: 'index',
						align: 'center',
						width: '70px',
						columnSetDisabled: true, //禁止在列设置中选择
						//@ts-ignore
						formatter: (context) => {
							//计算序号,你可以自定义计算规则，此处为翻页累加
							let index = context.index ?? 1;
							let pagination: any = crudExpose!.crudBinding.value.pagination;
							return ((pagination.currentPage ?? 1) - 1) * pagination.pageSize + index + 1;
						},
					},
				},

				C62XLV2:{
					column:{
						sortable:true
					},
					search:{
						show:true,
						component: {
							props: {
								clearable: true,
							},
							placeholder: '请输入关键词',
						},
					},
					title:'C62X-LV2'
				},
				C62XLV3:{
					column:{
						sortable:true
					},
					search:{
						show:true,
						component: {
							props: {
								clearable: true,
							},
							placeholder: '请输入关键词',
						},
					},
					title:'C62X-LV3'
				},
				C62XLV4:{
					column:{
						sortable:true
					},
					search:{
						show:true,
						component: {
							props: {
								clearable: true,
							},
							placeholder: '请输入关键词',
						},
					},
					title:'C62X-LV4'
				},
				C62XLV1MT:{
					column:{
						sortable:true
					},
					search:{
						show:true,
						component: {
							props: {
								clearable: true,
							},
							placeholder: '请输入关键词',
						},
					},
					title:'C62X-LV1 MT'
				},
				C62XLV17DCT:{
					column:{
						sortable:true
					},
					search:{
						show:true,
						component: {
							props: {
								clearable: true,
							},
							placeholder: '请输入关键词',
						},
					},
					title:'C62X-LV1-7DCT'
				},

				station:{
					type:'link',
					column:{
						sortable:true,
						component:{
							on:{
								onClick({row,key}:any){
									// 此处的key是"gong_wei",需求的key是"station",所以做了手动生成
									const query = {
										station:row[key]
									}

									router.push({name:'工位信息', query})

								}
							}
						}
					},
					title:'工位',
					search:{
						show:true,
						component: {
							props: {
								clearable: true,
							},
							placeholder: '请输入关键词',
						},
					},
				},

				ling_bu_jian_hao:{
					column:{
						sortable:true
					},
					title:'零部件号',
					search:{
						show:true,
						component: {
							props: {
								clearable: true,
							},
							placeholder: '请输入关键词',
						},
					},
				},
				ling_bu_jian_zhong_wen_ming_cheng:{
					title:'零部件中文名称',
					search:{
						show:true,
						component: {
							props: {
								clearable: true,
							},
							placeholder: '请输入关键词',
						},
					},
				},

				ling_bu_jian_ying_wen_ming_cheng:{
					title:'零部件英文名称',
					search:{
						show:true,
						component: {
							props: {
								clearable: true,
							},
							placeholder: '请输入关键词',
						},
					},
				},
				dan_wei_yong_liang:{
					title:'单位用量',
				},
				ling_jian_zhi_liang_kg_dan_wei:{
					column:{
						sortable:true
					},
					title:'零件质量kg/单位',
				},
				cai_liao:{
					type:'link',
					column:{
						sortable:true,
						component:{
							on:{
								onClick({row,key}:any){
									let query = {
										[key]:row[key]
									}
									router.push({name:'材料信息', query})

								}
							}
						}
					},
					title:'材料',
				},
				liao_hou_mm:{
					column:{
						sortable:true
					},
					title:'料厚mm',
				},
				guan_jian_zhi_liang_te_xing:{
					column:{
						sortable:true
					},
					title:'关键质量特性',
				},

				ji_bie:{
					title:'级别',
				},
			},
		},
	};
};
